home *** CD-ROM | disk | FTP | other *** search
/ Dr. Windows 3 / dr win3.zip / dr win3 / PROGRAMR / 3DLIB30A.ZIP / RTOBJ.INT < prev    next >
Text File  |  1994-03-10  |  9KB  |  217 lines

  1. (******************************************************************************
  2. *                                    rtObj                                    *
  3. *      please notice -                                                        *
  4. *      this unit includes both the object3d unit, and the superobj unit,      *
  5. *      and it is used with no reference to the WWToolKit window GUI library,  *
  6. *      uses project3, instead of prjWind  (It does, however, support OWL)     *
  7. *                                                                             *
  8. * In V2.x - The support collections are part of this unit as well ...         *
  9. * V3.x adds os/2 support                                                      *
  10. ******************************************************************************)
  11. Unit rtObj;
  12. {$ifdef os2}
  13. {$X+}
  14. {$endif}
  15.  
  16. (*******************************************************************************
  17. *                                 3D Objects                                   *
  18. *                                 ----------                                   *
  19. *                                                                              *
  20. *   A 3D object is a collection of points and lines in the 3D universe,        *
  21. *   that represent the body we want to draw on the screen.                     *
  22. *   A 3D object is allways centered around point (0, 0, 0) in the 3D universe. *
  23. *   (Its center of gravity assuming it is has a uniform weight distribution    *
  24. *    is in point (0, 0, 0)                                                     *
  25. *   At any moment during the object's life, we know it's distance from the     *
  26. *   origin, And it's rotation using reveres rotation CTM.                      *
  27. *                                                                              *
  28. *   3D Object methods:                                                         *
  29. *      constructor Open                                                        *
  30. *      destructor  CloseMe                                                     *
  31. *      procedures: Rotate, Scale, Move, Show, Hide, Load, Save                 *
  32. *                  SetToOrigin, Paint                                          *
  33. *                                                                              *
  34. *******************************************************************************)
  35.  
  36. interface
  37.  
  38. uses
  39. {$ifdef windows}
  40.     winTypes
  41.     ,winProcs
  42. {$else}
  43.  {$ifdef os2}
  44.     os23dsup
  45.  {$else}
  46.     graph
  47.  {$endif}
  48. {$endif}
  49.     ,Ctm3d
  50.     ,hdr3d
  51.     ,project3
  52.     ,objects { needed for collection support .. }
  53.     ;
  54.  
  55. type
  56.    P3dPointCollection = ^ T3dPointCollection;
  57.    T3dPointCollection = object(TCollection)
  58.  
  59.       procedure freeItem(item : pointer); virtual;
  60.  
  61.    end; { T3dPointCollection definition .. }
  62.  
  63.    P3dLineCollection = ^ T3dLineCollection;
  64.    T3dLineCollection = object(TCollection)
  65.  
  66.       procedure freeItem(item : pointer); virtual;
  67.  
  68.    end; { T3dLineCollection definition .. }
  69.  
  70.    PScreenPointsCollection = ^ TScreenPointsCollection;
  71.    TScreenPointsCollection = object(TCollection)
  72.  
  73.       procedure freeItem(item : pointer); virtual;
  74.  
  75.    end; { TScreenPointsCollection definition .. }
  76.  
  77. type
  78. {$ifdef os2}
  79.    f_real = file;
  80. {$else}
  81.     f_real = file of real;
  82. {$endif}
  83.  
  84.     {===================================================================}
  85.     {  Base object is the base class for 3D-objects. some functions     }
  86.     { are dummy virtual do-nothing, which are are implemented only for  }
  87.     { the descendend objects derived from BaseObject                    }
  88.     {===================================================================}
  89.  
  90.     BaseObjectPtr = ^BaseObject;
  91.     BaseObject = object
  92.        MyCtm       : Ctm;      { This CTM applied to the object gives the  }
  93.                                {  objects Position after transformations   }
  94.        Name        : String;   { Identifies the object                     }
  95.        myColor     : word;     { Main color for the object                 }
  96.        Location    : point3d;  { Central of gravity in real space          }
  97.        scrPntUpdt  : boolean;  { True if screen points updated             }
  98.  
  99.        constructor open(myName : string; color : word);
  100.        destructor  CloseMe; virtual;
  101. {$ifdef windows}
  102.        procedure   show(dc : hdc); virtual;
  103.        procedure   hide(dc : hdc); virtual;
  104.        procedure   paint(dc : hdc); virtual; {in specified color}
  105. {$else}
  106.  {$ifdef os2}
  107.        procedure   show(ps : hps); virtual;
  108.        procedure   hide(ps : hps); virtual;
  109.        procedure   paint(ps : hps); virtual; {in specified color}
  110.  {$else}
  111.        procedure   show; virtual;
  112.        procedure   hide; virtual;
  113.        procedure   paint; virtual; {in specified color}
  114.  {$endif}
  115. {$endif}
  116.        procedure   updateScreenPoints; virtual; {transform object 3D -> 2D}
  117.        procedure   move(axis : axisType; by : real); virtual;
  118.        procedure   translate(dx, dy, dz : integer); virtual;
  119.                {multy dimentional move in 1 call}
  120.        procedure   scale(axis : axisType; factor : real); virtual;
  121.        procedure   allScale(sx, sy, sz : real); virtual;
  122.                {multy dimentional scale in 1 call}
  123.        procedure   rotate(axis : axisType; deg : real); virtual;
  124.  
  125.        procedure   goto3dPos(x, y, z : real); virtual; {translate to absolute place}
  126.        procedure   setToOrigin; virtual;
  127.                {translate to 0,0,0, update points, and set myCtm to unit}
  128.        procedure   calcLocation; virtual; {set Location to central gravity}
  129.        procedure   deleteTransform; virtual; {set MyCtm to unit}
  130.  
  131.        function load : word; virtual; {from disk}
  132.        function save : word; virtual; {to   disk}
  133.        procedure writeMe(var elementFile : f_real); virtual; {to disk .. without opening file..}
  134.        procedure readMe(var elementFile : f_real); virtual;
  135.     end;
  136.  
  137.     {===================================================================}
  138.     { Obj3d is an object which represents a 3-D object with a poligon  }
  139.     {  mesh.                                                           }
  140.     {===================================================================}
  141.  
  142.     Obj3dPtr = ^Obj3d;
  143.     Obj3d = object(BaseObject)
  144. (*       Points      : array[1..MaxPoints] of point3d; *)
  145.        Points      : T3dPointCollection; 
  146. (*       Lines       : array[1..MaxLines]   of Line3d; *)
  147.        Lines       : T3dLineCollection;
  148. (*       scrPoints   : array[1..MaxPoints] of screenPoints; *)
  149.        scrPoints   : TScreenPointsCollection;
  150.        NumOfLines  : integer;
  151.        NumOfPoints : integer;
  152.        ReverseRot  : Ctm;  { Saves only the reverse rotations }
  153.        unReverseRot: Ctm;  { reverse of the above}
  154.  
  155.        constructor open(myName : string; ref : point3d; color : word);
  156.        destructor  CloseMe; virtual;
  157. {$ifdef windows}
  158.        procedure   paint(dc : hdc); virtual; {in specified color}
  159. {$else}
  160.  {$ifdef os2}
  161.        procedure   paint(ps : hps); virtual; {in specified color}
  162.  {$else}
  163.        procedure   paint; virtual; {in specified color}
  164.  {$endif}
  165. {$endif}
  166.        procedure   updateScreenPoints; virtual; {transform object 3D -> 2D}
  167.  
  168.        procedure   calcLocation; virtual; {set Location to central gravity}
  169.        procedure   setToOrigin; virtual;
  170.  
  171.        procedure writeMe(var elementFile : f_real); virtual;
  172.        procedure readMe(var elementFile : f_real); virtual;
  173.     end;
  174.  
  175. const
  176.    maxSubObjects = 15;
  177.  
  178. type
  179.     complexObjPtr = ^complexObj;
  180.     ComplexObj = object(BaseObject)
  181.        childs      : array [1..maxSubObjects] of obj3dPtr;
  182.        ctms        : array [1..maxSubObjects] of ctm;
  183.        numOfChilds : integer; {counter of # of obj3d childs}
  184.  
  185.        constructor open(myName : string; color : word);
  186.        destructor  closeMe; virtual;
  187.        procedure   updateScreenPoints; virtual;
  188.        procedure   writeMe(var elementFile : f_real); virtual;
  189.        procedure   readMe(var elementFile : f_real); virtual;
  190.        procedure   calcLocation; virtual;
  191. {$ifdef WINDOWS}
  192.        procedure